import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ManagerLoad extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JLabel textgd1;
	private JTextField textyhm;
	private JTextField textmm;
	private JButton btnNewButton;
	private JButton btnNewButton_1;
	private JTextField textField_2;
	private JTextField textField_3;


	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ManagerLoad frame = new ManagerLoad();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	ManagerLoad() {
		getContentPane().setFont(new Font("宋体", Font.PLAIN, 16));
		setTitle("用户登录");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(null);

		JLabel lblNewLabel_1 = new JLabel("用户名");
		lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 20));
		lblNewLabel_1.setBounds(49, 60, 68, 24);
		getContentPane().add(lblNewLabel_1);

		JLabel lblNewLabel = new JLabel("密码");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 20));
		lblNewLabel.setBounds(49, 123, 54, 24);
		getContentPane().add(lblNewLabel);

		textField_2 = new JTextField();
		textField_2.setBounds(160, 64, 135, 21);
		getContentPane().add(textField_2);
		textField_2.setColumns(10);

		textField_3 = new JTextField();
		textField_3.setBounds(160, 127, 135, 21);
		getContentPane().add(textField_3);
		textField_3.setColumns(10);

		JButton btnNewButton_2 = new JButton("清空");
		btnNewButton_2.setFont(new Font("宋体", Font.PLAIN, 16));
		btnNewButton_2.setBounds(74, 191, 93, 35);
		getContentPane().add(btnNewButton_2);
		btnNewButton_2.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				textField_2.setText("");
				textField_3.setText("");
			}
		});

		JButton btnNewButton_3 = new JButton("登录");
		btnNewButton_3.setFont(new Font("宋体", Font.PLAIN, 16));
		btnNewButton_3.setBounds(257, 191, 93, 35);
		getContentPane().add(btnNewButton_3);
		contentPane = new JPanel();
		btnNewButton_3.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String username = textField_2.getText();
				String password = textField_3.getText();

				System.out.println("⽤户名:" + username);
				System.out.println("密码:" + password);
				CustomerDao GoodsAddFrame = new CustomerDao();
				Customer Customer = null;
				try {
					Customer = GoodsAddFrame.login(username, password);
				} catch (Exception e1) {
					e1.printStackTrace();
				}
				if (Customer == null) {
					// 弹窗提示
					JOptionPane.showMessageDialog(null, "登录失败，请重新输⼊");
				} else {
					ManageFrame manage = new ManageFrame();
					manage.setVisible(true);
					setVisible(false);

				}
			}
		});

	}

}

